<h1><?php echo Yii::t('user','Cài đặt hệ thống Quản trị Thành viên') ?></h1>
<h2><?php echo Yii::t('user','Bước 3/4: Tạo tài khoản quản trị.') ?></h2>

<script src="<?php echo bu() ?>/js/GeneratePassword.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" charset="utf-8">
	function updateNameField()
	{
		var first_name = $("#CreateUserForm_first_name").val();
		var last_name = $("#CreateUserForm_last_name").val();
		var $input = $("#CreateUserForm_name_option");
		$input.find('> option:eq(0)').text(first_name + ' ' + last_name);
		$input.find('> option:eq(1)').text(last_name + ' ' + first_name);
		if(first_name!='' && last_name!='') $input.parent().slideDown('fast');
		else $input.parent().slideUp('fast');
	}
	
	function autoPassword()
	{
		var sPassword = GeneratePassword();
		$("#CreateUserForm_password").val(sPassword);
		$("#autoPassword").html('Mặt khẩu tự động: <strong>' + sPassword + '</strong>').slideDown('fast');
	}
</script>

<h1><?php echo Yii::t('backend','Thêm thành viên mới'); ?></h1>

<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'create-user-form-create_user_form-form',
    'enableAjaxValidation'=>false,
	'focus'=>Utils::AutoFocus($model, 'first_name')
)); ?>

    <?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'group_id'); ?>
		<?php echo $form->dropDownList($model, "group_id", CHtml::listData(UserGroup::model()->findAll(),"id","name")); ?>
	</div>
	
    <div class="row">
        <?php echo $form->labelEx($model,'first_name'); ?>
        <?php echo $form->textField($model,'first_name', array('onkeyup'=>'updateNameField()')); ?>
        <?php echo $form->error($model,'first_name'); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model,'last_name'); ?>
        <?php echo $form->textField($model,'last_name', array('onkeyup'=>'updateNameField()')); ?>
        <?php echo $form->error($model,'last_name'); ?>
    </div>
    <div class="row <?php echo ($model->first_name!='' && $model->last_name!='') ? "":"hide" ?>">
        <?php echo $form->labelEx($model,'name'); ?>
        <?php echo $form->dropDownList($model,'name_option', array('0'=>$model->first_name . ' ' . $model->last_name, '1'=>$model->last_name . ' ' . $model->first_name)); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model,'password'); ?>
        <?php echo $form->passwordField($model,'password'); ?>
		<?php echo CHtml::link(Yii::t('user','Tự tạo mật khẩu'), '#', array('onclick'=>'autoPassword(); return false;')) ?>
		<p id="autoPassword" class="hint hide"></p>
        <?php echo $form->error($model,'password'); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model,'email'); ?>
        <?php echo $form->textField($model,'email'); ?>
        <?php echo $form->error($model,'email'); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model,'sendWelcomeEmail'); ?>
        <?php echo $form->checkBox($model,'sendWelcomeEmail'); ?>
		<p class="hint">
			<?php echo Yii::t('user','Một email chứa thông tin đăng nhập sẽ được gửi đến địa chỉ email của thành viên này.') ?>
		</p>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton(Yii::t('backend','Thêm thành viên mới'), array('class'=>'g-button g-button-submit')); ?>
    </div>

<?php $this->endWidget(); ?>
</div><!-- form -->